import fetch from '~common/fetch';
import { IDirInfo, IDirFileInfo } from '~service/type';

export * from '~service/type';

// as api
export default {
    async getDirInnerAllFiles(params: { dirpath: string }) {
        return fetch.post<IDirInfo>({ url: '/getDirInnerAllFiles', data: params });
    },

    async getDirInnerFiles(params: { dirpath: string; isDeep: boolean }) {
        return fetch.post<IDirFileInfo>({ url: '/getDirInnerFiles', data: params });
    },

    async createFolder(params: { dirpath: string }) {
        return fetch.post<null>({ url: '/createFolder', data: params });
    },

    async transferFolder(params: { from: string; to: string; overwrite?: boolean }) {
        return fetch.post<null>({ url: '/transferFolder', data: params });
    },

    async deleteFolder(params: { dirpaths: string[] }) {
        return fetch.post<null>({ url: '/deleteFolder', data: params });
    },

    async transferFile(params: { list: Array<{ from: string; to: string }>; overwrite?: boolean }) {
        return fetch.post<null>({ url: '/transferFile', data: params });
    },

    async deleteFile(params: { filepaths: string[] }) {
        return fetch.post<null>({ url: '/deleteFile', data: params });
    },

    async renameFileOrFolder(params: { oldpath: string; newpath: string }) {
        return fetch.post<null>({ url: '/renameFileOrFolder', data: params });
    },

    async copyFileOrFolder(params: { list: Array<{ from: string; to: string }>; overwrite?: boolean }) {
        return fetch.post<null>({ url: '/copyFileOrFolder', data: params });
    },
};
